package com.das.mechanic_base.adapter.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.main.DetailByCarBrandAndQuestionBean;

import java.util.List;

public class X3DetectionAloneAdapter extends RecyclerView.Adapter<X3DetectionAloneAdapter.DetectionAloneHolder> {

    private List<List<DetailByCarBrandAndQuestionBean.BrandAmountVoBean>> mList;

    private Context mContext;

    private int showType;

    /**
     * 0 车辆品牌
     * 1 检测项/检测点
     */
    private int type;

    public X3DetectionAloneAdapter(List<List<DetailByCarBrandAndQuestionBean.BrandAmountVoBean>> mList, Context mContext, int type) {
        this.mList = mList;
        this.mContext = mContext;
        this.type = type;
    }

    public void changeShowType(int showType) {
        this.showType = showType;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public DetectionAloneHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new DetectionAloneHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_detection_alone_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull DetectionAloneHolder holder, int position) {

        holder.rlv_item.setLayoutManager(new LinearLayoutManager(mContext));
        X3DetectionAloneItemAdapter itemAdapter;
        if (type == 0) {
            itemAdapter = new X3DetectionAloneItemAdapter(mList.get(position),mContext,type,position);
        }else {
            if (position == 0) {
                itemAdapter = new X3DetectionAloneItemAdapter(mList.get(position),mContext,1,0);
            }else {
                itemAdapter = new X3DetectionAloneItemAdapter(mList.get(position),mContext,1,1);
            }
        }
        holder.rlv_item.setAdapter(itemAdapter);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class DetectionAloneHolder extends RecyclerView.ViewHolder {
        RecyclerView rlv_item;
        public DetectionAloneHolder(@NonNull View itemView) {
            super(itemView);
            rlv_item = itemView.findViewById(R.id.rlv_item);
        }
    }
}
